<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>大灰狼会员设备清空</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            width: 90%;
            max-width: 400px;
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        h1 {
            font-size: 24px;
            margin-bottom: 20px;
            color: #333;
        }

        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 12px;
            margin: 10px 0;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }

        .btn {
            width: 100%;
            padding: 12px;
            margin: 10px 0;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
        }

        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }

        .btn-secondary {
            background-color: #f44336;
            color: white;
        }

        .btn:disabled {
            background-color: #ccc;
            cursor: not-allowed;
        }

        .message {
            margin-top: 15px;
            font-size: 14px;
            color: #333;
        }
    </style>
</head>
<body>

    <div class="container">
        <h1>大灰狼会员设备清空</h1>
        <input type="text" id="key" placeholder="输入密钥">
        <input type="text" id="verificationCode" placeholder="输入验证码">
        <button class="btn btn-primary" id="getVerificationCodeBtn">获取验证码</button>
        <button class="btn btn-secondary" id="submitBtn">提交</button>

        <div class="message" id="message"></div>
    </div>

    <script>
        document.getElementById('getVerificationCodeBtn').addEventListener('click', function () {
            const key = document.getElementById('key').value;

            if (!key) {
                showMessage('请填写密钥');
                return;
            }

            // 发起获取验证码的请求
            fetch('/get_clear_code', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ key })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    showMessage(data.message);
                } else {
                    showMessage(data.message, true);
                }
            })
            .catch(error => {
                showMessage('获取验证码失败，请重试', true);
            });
        });

        document.getElementById('submitBtn').addEventListener('click', function () {
            const code = document.getElementById('verificationCode').value;
            const key = document.getElementById('key').value;

            if (!key || !code) {
                showMessage('请填写密钥和验证码');
                return;
            }

            // 发起提交请求
            fetch('/clear_vip', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ key, code })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    showMessage(data.message);
                } else {
                    showMessage(data.message, true);
                }
            })
            .catch(error => {
                showMessage('提交失败，请重试', true);
            });
        });

        function showMessage(message, isError = false) {
            const messageBox = document.getElementById('message');
            messageBox.textContent = message;
            messageBox.style.color = isError ? 'red' : 'green';
        }
    </script>

</body>
</html>